const mysql = require('mysql');
const pool = mysql.createPool({
    host: 'localhost',
    user: 'test',
    password: 'test',
    database: 'blog',
    connectionLimit: 10 // 连接池中连接的数量
});

function query(sql, values, callback) {
    pool.getConnection((err, connection) => {
        if (err) {
            return callback(err);
        }
        connection.query(sql, values, (error, results, fields) => {
            connection.release(); // 释放连接
            if (error) {
                return callback(error);
            }
            return callback(null, results);
        });
    });
}

module.exports = {
    query
};